/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    uart_test.c
 *  @brief   UART testcase source file
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#include "printf.h"
#include "hal_api.h"

#define TEST_CASE_WDT_TIMEOUT_S 10
#define TEST_WDT_OBJ WDT_ID_0

uint32_t kick_num = 0;

static void wdt_irq_handler(void *ptr)
{
	uint32_t wdt_id = (uint32_t)ptr;
	uint32_t timeout;

	printf("[WDT%lu]: wdt_irq_handler\r\n", wdt_id);

	if (kick_num == 0) {
		Hal_Wdt_Kick(wdt_id);
		timeout = Hal_Wdt_GetTimeleft(TEST_WDT_OBJ);
		printf("[WDT]: watchdog will timeout after %lu seconds\r\n", timeout);
		kick_num++;
	}
}

int32_t test_wdt(void)
{
	uint32_t timeout;

	printf("\r\n[WDT]: TEST START\r\n");

	Hal_Wdt_RegisterCb(wdt_irq_handler);
	Hal_Wdt_Start(TEST_WDT_OBJ, TEST_CASE_WDT_TIMEOUT_S);

	timeout = Hal_Wdt_GetTimeleft(TEST_WDT_OBJ);
	printf("[WDT]: watchdog will timeout after %lu seconds\r\n", timeout);

	return 0;
}

